package com.qf.mywatch.adapter;

import android.content.Context;
import android.support.v4.view.PagerAdapter;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import java.util.ArrayList;

/**
 * Created by Administrator on 2016/12/14.
 */
//图片轮播适配器
public class MyPageAdaper extends PagerAdapter {

    private ArrayList<ImageView> list;
    private Context context;

    public MyPageAdaper(Context context, ArrayList<ImageView> list) {
        this.list = list;
        this.context = context;
    }

    public MyPageAdaper(ArrayList<ImageView> list) {
        this.list = list;
    }

    @Override
    public int getCount() {
        return list==null?0:list.size();
    }

    @Override
    public boolean isViewFromObject(View view, Object object) {
        return view == object;
    }

    @Override
    public Object instantiateItem(ViewGroup container, int position) {
        View view = list.get(position);
        container.addView(view);
        return view;
    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        container.removeView(list.get(position));
    }
}
